<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;

//require __DIR__.'/../../models/Order.class'

class CreateOrderTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		//订单
		Schema::create('order', function(Blueprint $table){
				$table->increments('id');
				$table->string('order_no', 60);//订单号
				$table->string('title', 50);
				$table->decimal('price',11,2);
				$table->integer('score_cut')->default(0);
				$table->integer('qty')->defaults(0);//商品数量
				$table->integer('user_id');
				$table->string('phone', 30);//手机号
				$table->smallInteger('state')->default(0);//订单状态
				$table->text('memo');
				$table->integer('workflow_id')->defaults(0);
				$table->smallInteger('pay_status')->defaults(0);//支付状态
				$table->timestamps();
			});
			Schema::create('order_item', function(Blueprint $table){
				$table->increments('id');
				$table->integer('order_id');
				$table->integer('product_id');
				$table->decimal('price',11,2);
				$table->integer('qty')->defaults(0);
				$table->timestamps();
			});
			
			//结算
			Schema::create('balance', function (Blueprint $table){
				$table->increments('id');
				$table->integer('order_id');
				$table->decimal('amount',11,2);
				$table->integer('pay_method');//支付方式
				$table->integer('pay_status')->default(0);
				$table->timestamps();
			});
			//用户已购买商品
			Schema::create('user_product', function (Blueprint $table){
				$table->increments('id');
				$table->integer('user_id');
				$table->integer('product_id');
				$table->integer('qty');
				$table->timestamps();
			});
			
				//工作流
				Schema::create('workflow',function(Blueprint $table){
					$table->increments('id');
					$table->integer('order_id');
					$table->integer('workflow_node_id');
					$table->integer('user_id');
					$table->string('user_name', 30);
					$table->string('memo',200);
					$table->timestamps();
				});
				Schema::create('workflow_node', function(Blueprint $table){
					$table->increments('id');
					$table->string('name', 30);//节点名称
					$table->string('operate',200);//设置订单状态值 colnum1=value1[, column2=value2...]
					$table->string('condition',120);//满足条件: colnum1=value1[ (&& | || ) column2=value2 ...]
					$table->integer('act_order');
					$table->string('route', 30);
					$table->string('display_name',50)->defaults('');
				});
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		//
	}

}
